package com.cy.store.controller;

import com.cy.store.entity.Product;
import com.cy.store.service.IProductService;
import com.cy.store.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("products")
public class ProductController extends BaseController {
    @Autowired
    private IProductService productService;

    //显示热销商品
    @RequestMapping("hot_list")
    public JsonResult<List<Product>> getHotList(){
        return new JsonResult<List<Product>>(OK, productService.findHotList());
    }

    //显示商品详情
    @RequestMapping("{id}/details")
    public JsonResult<Product> getById(@PathVariable("id") Integer id){
        return new JsonResult<>(OK, productService.findById(id));
    }
}
